$(function(){
			getFirstType();
			$("#faqtypes dd a").on("click",function(){
				getFaqs(this);
			});
		});
		
		function getFaqs(faqtypes){
			var url = $(faqtypes).attr("data-url");
			$.get(url,function(data){
				var faqs = data.faqs;
				var faq_container = $("#faq_container");
				faq_container.empty();
				$.each(faqs,function(index,element){
					var li = $("<li/>");
					var a = $("<a/>",{text:element.question,"href":"javascript:void(0)","data-index":element.id});
					a.appendTo(li);
					li.append("<div class=\"faq-content\">"+ element.answer +"</div>");
					faq_container.append($(li));
				});
				getFaq();
			});
		}
		
		function getFirstType(){
			var first_types = $("#faqtypes dd a");
			if(first_types!=undefined){
				var first_type = first_types[0];
				getFaqs(first_type);
			}
		}
		
		function getFaq(){
			$("#faq_container li a").on("click",function(){
				var index = $(this).attr("data-index");
				var content = $(this).parent().find(".faq-content");
				if(content!=undefined){
					var display = $(content).css("display");
					if("none"==display){
						$.get("faq_"+index+".jspx");
						$(content).css("display","block");
					}else{
						$(content).css("display","none");
					}
				}
			});
		}